package megrez.boot.autoconfigure.aliyun;

import java.time.Duration;

import org.springframework.boot.context.properties.ConfigurationProperties;

import com.aliyun.teaopenapi.models.Config;

import lombok.Data;
import lombok.ToString;

/**
 * 属性配置
 * 
 * @author Lucky Yang
 * @since 2.6.9
 * 
 * @see com.aliyun.teaopenapi.models.Config
 */
@Data
@ConfigurationProperties(prefix = "aliyun.config")
public class ConfigProperties {
    // accesskey id
    @ToString.Exclude
    private String accessKeyId;

    // accesskey secret
    @ToString.Exclude
    private String accessKeySecret;

    // security token
    private String securityToken;

    // http protocol
    private String protocol;

    // http method
    private String method;

    // region id
    private String regionId;

    // read timeout
    private Duration readTimeout;

    // connect timeout
    private Duration connectTimeout;

    // http proxy
    private String httpProxy;

    // https proxy
    private String httpsProxy;

    // endpoint, 必须的
    private String endpoint = "127.0.0.1";

    // proxy white list
    private String noProxy;

    // max idle conns
    private Integer maxIdleConns;

    // network for endpoint
    private String network;

    // user agent
    private String userAgent;

    // suffix for endpoint
    private String suffix;

    // socks5 proxy
    private String socks5Proxy;

    // socks5 network
    private String socks5NetWork;

    // endpoint type
    private String endpointType;

    // OpenPlatform endpoint
    private String openPlatformEndpoint;

    // credential type
    private String type;
    // Signature Version
    private String signatureVersion;

    // Signature Algorithm
    private String signatureAlgorithm;

    public Config convert(Config config) {
        config.setAccessKeyId(accessKeyId).setAccessKeySecret(accessKeySecret).setSecurityToken(securityToken)
                .setProtocol(protocol).setMethod(method).setRegionId(regionId).setReadTimeout(maxIdleConns)
                .setConnectTimeout(maxIdleConns)
                .setHttpProxy(httpProxy).setHttpsProxy(httpsProxy).setEndpoint(endpoint).setNoProxy(noProxy)
                .setMaxIdleConns(maxIdleConns)
                .setNetwork(network).setUserAgent(userAgent).setSuffix(suffix).setSocks5Proxy(socks5Proxy)
                .setSocks5NetWork(socks5NetWork)
                .setEndpointType(endpointType).setOpenPlatformEndpoint(openPlatformEndpoint).setType(endpointType)
                .setSignatureVersion(signatureVersion).setSignatureAlgorithm(signatureAlgorithm);

        return config;
    }

}
